print backend: Fix list model handling in dispose
authorMatthias Clasen <mclasen@redhat.com>
Mon, 1 Jun 2020 11:43:54 +0000 (07:43 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 1 Jun 2020 17:52:21 +0000 (13:52 -0400)
The print backends do some complicated dispose handling
where the implementations call gtk_print_backend_destroy().

Our tests (in particular, the templates test) trigger
situations where we use print backends after dispose,
and they can't handle the printers listmodel being
NULL at that time. So just remove the printers in
dispose, keep the empty liststore until finalize.

gtk/gtkprintbackend.c

index eadd4125d5f0e4ea408efbc901275e4d2e6fdef8..2071379a1bffce1333bc07912abb4b8770862500 100644 (file)
@@ -29,6 +29,7 @@
 #include "gtkprintbackendprivate.h"
 
 
+static void gtk_print_backend_finalize     (GObject      *object);
 static void gtk_print_backend_dispose      (GObject      *object);
 static void gtk_print_backend_set_property (GObject      *object,
                                             guint         prop_id,
@@ -251,6 +252,7 @@ gtk_print_backend_class_init (GtkPrintBackendClass *class)
 
   backend_parent_class = g_type_class_peek_parent (class);
   
+  object_class->finalize = gtk_print_backend_finalize;
   object_class->dispose = gtk_print_backend_dispose;
   object_class->set_property = gtk_print_backend_set_property;
   object_class->get_property = gtk_print_backend_get_property;
@@ -348,11 +350,21 @@ gtk_print_backend_dispose (GObject *object)
   /* We unref the printers in dispose, not in finalize so that
    * we can break refcount cycles with gtk_print_backend_destroy 
    */
-  g_clear_object (&priv->printers);
+  g_list_store_remove_all (priv->printers);
 
   backend_parent_class->dispose (object);
 }
 
+static void
+gtk_print_backend_finalize (GObject *object)
+{
+  GtkPrintBackend *backend = GTK_PRINT_BACKEND (object);
+  GtkPrintBackendPrivate *priv = backend->priv;
+
+  g_clear_object (&priv->printers);
+
+  backend_parent_class->finalize (object);
+}
 
 static void
 fallback_printer_request_details (GtkPrinter *printer)
@@ -361,7 +373,7 @@ fallback_printer_request_details (GtkPrinter *printer)
 
 static gboolean
 fallback_printer_mark_conflicts (GtkPrinter          *printer,
-                                GtkPrinterOptionSet *options)
+                                 GtkPrinterOptionSet *options)
 {
   return FALSE;
 }